﻿CREATE PROCEDURE [dbo].[EmailQueue_Put]
	@emailQueueId INT, 
	@errorText NVARCHAR(max) = null
AS
BEGIN
	DECLARE @date DATETIME
	SET @date = getdate()

	IF (@errorText is null)
	BEGIN
		UPDATE [dbo].[email_Queue]
			 SET [RequestDate] = NULL
					,[SendDate] = @date
		 WHERE [EmailQueueId] = @emailQueueId
	END
	ELSE
	BEGIN
		UPDATE [dbo].[email_Queue]
			 SET [RequestDate] = NULL
					,[ErrorDate] = @date
					,[ErrorCount] = [ErrorCount] + 1
					,[ErrorText] = @errorText
		 WHERE [EmailQueueId] = @emailQueueId
 	END
END